package com.example.beson.androiddemo;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class DetailActivity extends AppCompatActivity {

    private String detailStr;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        detailStr="最佳UI体验";
        Toolbar detail_toolbar= (Toolbar) findViewById(R.id.detail_toolbar);
        CollapsingToolbarLayout collapshing_toolbar= (CollapsingToolbarLayout) findViewById(R.id.collapshing_toolbar);
        ImageView detail_image= (ImageView) findViewById(R.id.detail_image);
        TextView detail_content_text = (TextView) findViewById(R.id.detail_content_text);
        FloatingActionButton detail_floating= (FloatingActionButton) findViewById(R.id.detail_floating);
        setSupportActionBar(detail_toolbar);

        ActionBar actionBar=getSupportActionBar();
        if(actionBar!=null){
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.mipmap.choice_icon);
        }
        collapshing_toolbar.setTitle(detailStr);
        collapshing_toolbar.setCollapsedTitleTextColor(Color.RED);//是收缩后的颜色值
        collapshing_toolbar.setExpandedTitleColor(Color.GREEN);//是展开后的颜色值
        String detailContent=GetContent(detailStr);
        detail_content_text.setText(detailContent);
        detail_floating.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar.make(v,detailStr,Snackbar.LENGTH_SHORT).show();
            }
        });
    }
    private String GetContent(String detailStr){
        StringBuilder detailcontent=new StringBuilder();
        for(int i=0;i<100;i++){
            detailcontent.append(detailStr);
        }
        return detailcontent.toString();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
            default:
                break;
        }
        return true;
    }
}
